import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/order/order-item';


export interface OrderItemParam {
    orderId?: string;
    orderNo?: string;
    productId?: string;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface OrderItemResponse {
    id?: number;
    orderId: string;
    orderNo: string;
    productId?: string;
    categoryId?: string;
    skuId?: string;
    skuName?: number;
    skuPic?: number;
    skuPrice?: string;
    quantity?: number;
    skuAttrs?: string;
    promotionActivityId?: number;
    promotionAmount?: string;
    couponAmount?: string;
    pointAmount?: string;
    realAmount?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface OrderItemSaveCommand {
    id?: number;
    orderId: string;
    orderNo: string;
    productId?: string;
    categoryId?: string;
    skuId?: string;
    skuName?: number;
    skuPic?: number;
    skuPrice?: string;
    quantity?: number;
    skuAttrs?: string;
    promotionActivityId?: number;
    promotionAmount?: string;
    couponAmount?: string;
    pointAmount?: string;
    realAmount?: string;
}

export interface OrderItemResponseList {
    list: OrderItemResponse[];
    total: number;
}


// 通过OrderItemParam参数获取分页列表
export function pageOrderItem(params: OrderItemParam) {
    return axios.get<OrderItemResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取订单item信息
export function getOrderItem(id: number) {
    return axios.get<OrderItemResponse>(`${BASE_URL}/${id}`);
    
}

export function listOrderItem(params: OrderItemParam) {
    return axios.get<OrderItemResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加订单item
export function addOrderItem(params: OrderItemSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新订单item
export function updateOrderItem(params: OrderItemSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除订单item
export function deleteOrderItem(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}
